#ifndef SOFTJOY_H
#define SOFTJOY_H

#include <wx/scrolwin.h>
#include <wx/timer.h>
#include <wx/dc.h>
#include <wx/dcbuffer.h>

#define CURSOR_RADIUS 16
#define CURSOR_BORDER 2
#define MIN_MOVE_BACK 1
#define MAX_MOVE_BACK 2
#define EPS			  4
#define BACK_STEPS    4

BEGIN_DECLARE_EVENT_TYPES()
    DECLARE_EVENT_TYPE(wxEVT_SOFT_JOY_MOVE, -1)
	DECLARE_EVENT_TYPE(wxEVT_SOFT_JOY_BUTTON, -1)
END_DECLARE_EVENT_TYPES()

typedef void (wxEvtHandler::*wxJoyEventFunction)(wxJoystickEvent&);

#define EVT_SOFT_JOY_MOVE(id, fn) \
    DECLARE_EVENT_TABLE_ENTRY( \
        wxEVT_SOFT_JOY_MOVE, id, wxID_ANY, \
        (wxObjectEventFunction)(wxEventFunction) wxStaticCastEvent( wxJoyEventFunction, &fn ), \
        (wxObject *) NULL \
    ),

#define EVT_SOFT_JOY_BUTTON(id, fn) \
    DECLARE_EVENT_TABLE_ENTRY( \
        wxEVT_SOFT_JOY_BUTTON, id, wxID_ANY, \
        (wxObjectEventFunction)(wxEventFunction) wxStaticCastEvent( wxJoyEventFunction, &fn ), \
        (wxObject *) NULL \
    ),


class wxSoftJoy : public wxScrolledWindow
{
public:
	wxSoftJoy(wxWindow *parent, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize);
	~wxSoftJoy(void);

	void CentreCursor(void);
	void SetCursorColor(wxColor color)
	{m_CursorColor = color;
	InitImg();
	Refresh();}

protected:
	void InitImg(void);
	void DrawCurImage(wxDC &dst,wxDC &src,wxPoint &pos);
	void SaveCurImage(wxDC &dst,wxDC &src,wxPoint &pos);

protected:
	bool IsOnCursor(wxPoint &point);
	void PostCursorChangeEvent(wxPoint &point);
	void PostButtonChangeEvent(bool pressed);
	void PostMouseMoveEvent(wxPoint &point);
	wxPoint GetCenterPos(void);
	wxPoint Prescale(wxPoint pos);

protected:
	void DrawMetricAxis(wxDC &dc);
	void DrawCursor(wxDC &dc,wxPoint &pos,bool selected);
	void Draw(wxDC &dc);

protected:
	void OnSize(wxSizeEvent& evt);
	void OnMouse(wxMouseEvent& evt);
	virtual void OnDraw(wxDC &evt);
	void OnPosTimer(wxTimerEvent &evt);
	void OnEraseBackGround(wxEraseEvent& event) {};


private:
	wxPoint m_Offset;
	wxPoint m_Position;
	double m_VectX,m_VectY;
	double m_MoveVectX,m_MoveVectY;
	int m_BackMove;

	bool m_Selected;
	

	wxTimer m_Timer;

	wxBitmap m_SelCurImg;
	wxBitmap m_CurImg;
	wxBitmap m_BGImg;
	wxMemoryDC m_DCSelCurImg;
	wxMemoryDC m_DCCurImg;
	wxMemoryDC m_DCBGImg;

	wxColor m_CursorColor;

	DECLARE_EVENT_TABLE();
};


#endif //SOFTJOY_H